<?php

/**
*info:东软报修模板
*@author:yjj
*time:2017-03-28
*/
class RepaireastMsgtpl extends BaseMsgtpl
{
	/**
	 * 自动派单发送消息
	 * @param array $wechat		公众号信息
	 * @param array $order		订单信息
	 * @param array $repairman	维修工
	 * @return
	 */
	public function autoOperateSendMsg($order,$manager,$accountId)
	{
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id' => $manager), 'openid,subscribe,wechat_id');
		$url = C('site_url')."/repaireast/repaireastManager/orderDetail/repair_id/".$order['repair_id']."/order_id/".$order['order_id'];
		if ($accountId == 1) {
            //青橄榄测试
            $template_id = 'QoyqfE9ayEaJAjtSr6AOpYWNdX93lxwyCBw19gGmbbo';
        }else if($accountId == 39){
            //东软
			$template_id = 'Qy9uHHsRoe7dif8KouCRFWbBDxG-EnxnumkWrnX4fT8';
		}else if($accountId == 47){
            //海宁
            $template_id = 'GQV3ELwQOrTfeW1tFZusyBuBosRf90RJYPG4yCJ4BjI';
        }else if($accountId == 38){
            //中医药0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y
            $template_id = '0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y';
        }else if($accountId == 60){
            //云感测试
            $template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
        }else{
			$template_id = '';
		}

		//if($wechatUserInfo && $wechatUserInfo['subscribe']){
		if($accountId == 1){
			$info = array(
					'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
					'keyword1' => array("value" => $order['project_child_name'],"color" => "#173177" ),
					'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
					'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
					'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 39){
			$info = array(
				'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
				'keyword1' => array("value" => $order['real_name'] ),
				'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 47){
            $info = array(
                'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 38){
            $info = array(
                'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else{
			$info = array(
				'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
				'keyword1' => array("value" => $order['real_name'] ),
				/*'keyword3' => array("value" => date('Y-m-d H:i:s',strtotime("+1 hour")),"color" => "#173177" ),*/
				'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}

		$result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $info, $url);
		return $result;
		//}

		return false;
	}
	
	public function autoOperateToSendMsg($orderId,$manager,$accountId)
	{
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id' => $manager), 'openid,subscribe,wechat_id');
		$order = D('RepaireastOrder') -> where(array('order_id'=>$orderId)) -> field('type,repair_id,order_id,real_name,community_name,building_name,floor_name,room_name,project_child_name') -> find();
		$url = C('site_url')."/repaireast/repaireastManager/orderDetail/repair_id/".$order['repair_id']."/order_id/".$order['order_id'];
        if ($accountId == 1) {
            $template_id = 'QoyqfE9ayEaJAjtSr6AOpYWNdX93lxwyCBw19gGmbbo';
        }else if($accountId == 39){
			$template_id = 'Qy9uHHsRoe7dif8KouCRFWbBDxG-EnxnumkWrnX4fT8';
		}else if($accountId == 47){
            $template_id = 'GQV3ELwQOrTfeW1tFZusyBuBosRf90RJYPG4yCJ4BjI';
        }else if($accountId == 38){
            $template_id = '0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y';
        }else if($accountId == 60){
            //云感测试
            $template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
        }else{
			$template_id = '';
		}
		//判断是否是公共报修
		if($order['type'] == 2){
			$order['project_child_name'] = $order['public_name'];
		}
		//if($wechatUserInfo && $wechatUserInfo['subscribe']){
		if($accountId == 1){
			$info = array(
					'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
					'keyword1' => array("value" => $order['project_child_name'],"color" => "#173177" ),
					'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
					'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
					'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 39){
			$info = array(
				'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
				'keyword1' => array("value" => $order['real_name'] ),
				'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 47){
            $info = array(
                'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 38){
            $info = array(
                'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else{
			$info = array(
				'first' => array("value" => '您有新的派单，请即时指派！','color' => '#173177'),
				'keyword1' => array("value" => $order['real_name'] ),
				/*'keyword3' => array("value" => date('Y-m-d H:i:s',strtotime("+1 hour")),"color" => "#173177" ),*/
				'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}

		$result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $info, $url);
		return $result;
		//}

		return false;
	}
	
	/**
	 * 方法参数可以自己修改，添加--manager给维修工派单推送消息
	 * @param array $userData	用户信息
	 * @param array $orderInfo	订单信息
	 */
	public function orderConfirmSendMsg($orderId,$accountId,$repairworker_id)
	{
		$mOrder = D('RepaireastOrder');
		$orderInfo = $mOrder->getByOrderId($orderId);
		//维修工微信信息
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$repairworker_id), 'openid,subscribe');
		$url = C('site_url').'/index.php?g=repaireast&m=repaireastWorker&a=orderDetail&repair_id='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];
		//判断是否是公共报修
		if($orderInfo['type'] == 2){
			$orderInfo['project_child_name'] = $orderInfo['public_name'];
		}

		//if($wechatUserInfo['subscribe']) {
		if($accountId == 1){
			$array = array(
					'first' => array("value" => '您有一条新的订单，请即时维修！','color' => '#173177'),
					'keyword1' => array("value" => $orderInfo['project_child_name'],"color" => "#173177" ),
					'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
					'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
					'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 39){
			$array = array(
				'first' => array("value" => '您有一条新的订单，请即时维修！','color' => '#173177'),
				'keyword1' => array("value" => $orderInfo['real_name'] ),
				'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 47){
            $array = array(
                'first' => array("value" => '您有一条新的订单，请即时维修！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 38){
            $array = array(
                'first' => array("value" => '您有一条新的订单，请即时维修！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else{
			$array = array(
				'first' => array("value" => '您有一条新的订单，请即时维修！','color' => '#173177'),
				'keyword1' => array("value" => $orderInfo['real_name'] ),
				'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}


        if ($accountId == 1) {
            $template_id = 'QoyqfE9ayEaJAjtSr6AOpYWNdX93lxwyCBw19gGmbbo';
        }else if($accountId == 39){
			$template_id = 'Qy9uHHsRoe7dif8KouCRFWbBDxG-EnxnumkWrnX4fT8';
		}elseif($accountId == 47){
            $template_id = 'GQV3ELwQOrTfeW1tFZusyBuBosRf90RJYPG4yCJ4BjI';
        }else if($accountId == 38){
            $template_id = '0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y';
        }else if($accountId == 60){
            //云感测试
            $template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
        }
		$result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
	//}
		return $result;
			
	}
	
	/**
	 * 方法参数可以自己修改，添加--维修工接单后，推送消息给用户
	 * @param array $userData	用户信息
	 * @param array $orderInfo	订单信息
	 */
	public function orderToUserSendMsg($orderId,$accountId)
	{	
		$mOrder = D('RepaireastOrder');
		$orderInfo = $mOrder->getByOrderId($orderId);
		//用户微信信息
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$orderInfo['user_id']), 'openid,subscribe');
		$url = C('site_url').'/index.php?g=repaireast&m=repaireastRepair&a=orderDetail&repair_id='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];
		
			//判断是否是公共报修
		if($orderInfo['type'] == 2){
			$orderInfo['project_child_name'] = $orderInfo['public_name'];
		}
		
	//if($wechatUserInfo['subscribe']) {
		if($accountId == 1){
			$array = array(
					'first' => array("value" => '您的维修订单已接单！','color' => '#173177'),
					'keyword1' => array("value" => $orderInfo['project_child_name'],"color" => "#173177" ),
					'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
					'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
					'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 39){
			$array = array(
				'first' => array("value" => '您的维修订单已接单！','color' => '#173177'),
				'keyword1' => array("value" => $orderInfo['real_name'] ),
				'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 47){
            $array = array(
                'first' => array("value" => '您的维修订单已接单！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 38){
            $array = array(
                'first' => array("value" => '您的维修订单已接单！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else{
			$array = array(
				'first' => array("value" => '您的维修订单已接单！','color' => '#173177'),
				'keyword1' => array("value" => $orderInfo['real_name'] ),
				'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}


        if ($accountId == 1) {
            $template_id = 'QoyqfE9ayEaJAjtSr6AOpYWNdX93lxwyCBw19gGmbbo';
        }else if($accountId == 39){
			$template_id = 'Qy9uHHsRoe7dif8KouCRFWbBDxG-EnxnumkWrnX4fT8';
		}elseif($accountId == 47){
            $template_id = 'GQV3ELwQOrTfeW1tFZusyBuBosRf90RJYPG4yCJ4BjI';
        }else if($accountId == 38){
            $template_id = '0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y';
        }else if($accountId == 60){
            //云感测试
            $template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
        }
		$result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);

	//}
		return $result;
	}
	
	/**
	 * 订单完成处理 -- 订单完成推送消息给用户
	 * @param array $userData
	 * @param array $orderInfo
	 */
	public function orderFinishSendMsg($orderId,$accountId)
	{
		$mOrder = D('RepaireastOrder');
		//查询当前订单的信息
		$orderInfo = $mOrder->getByOrderId($orderId);
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$orderInfo['user_id']), 'openid,subscribe');
		//$url = C('site_url')."/base/repair/orderDetail/repairId/".$orderInfo['repair_id']."/order_id/".$orderInfo['order_id'];
		$url = C('site_url').'/index.php?g=repaireast&m=repaireastRepair&a=orderDetail&repair_id='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];
		
		//判断是否是公共报修
		if($orderInfo['type'] == 2){
			$orderInfo['project_child_name'] = $orderInfo['public_name'];
		}
		
	//if($wechatUserInfo['subscribe']) {
		if($accountId == 1){
			$array = array(
					'first' => array("value" => '您的维修订单已完成！','color' => '#173177'),
					'keyword1' => array("value" => $orderInfo['project_child_name'],"color" => "#173177" ),
					'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
					'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
					'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 39){
			$array = array(
				'first' => array("value" => '您的维修订单已完成！','color' => '#173177'),
				'keyword1' => array("value" => $orderInfo['real_name'] ),
				'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
				'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
				'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
				'remark' => array("value" => "点击查看详情！","color" => "#173177"),
			);
		}else if($accountId == 47){
            $array = array(
                'first' => array("value" => '您的维修订单已完成！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 38){
            $array = array(
                'first' => array("value" => '您的维修订单已完成！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else{
            $array = array(
                'first' => array("value" => '您的维修订单已完成！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }

        if ($accountId == 1) {
            $template_id = 'QoyqfE9ayEaJAjtSr6AOpYWNdX93lxwyCBw19gGmbbo';
        }else if($accountId == 39){
			$template_id = 'Qy9uHHsRoe7dif8KouCRFWbBDxG-EnxnumkWrnX4fT8';
		}else if($accountId == 47){
            $template_id = 'GQV3ELwQOrTfeW1tFZusyBuBosRf90RJYPG4yCJ4BjI';
        }else if($accountId == 38){
            $template_id = '0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y';
        }else if($accountId == 60){
            //云感测试
            $template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
        }
		$result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);

		return $result;
	//}
		return false;
	}

    /**
     * 订单取消处理 -- 维修工取消订单推送消息给用户
     * @param array $userData
     * @param array $orderInfo
     */
    public function orderCancelSendMsg($orderId,$accountId)
    {
        $mOrder = D('RepaireastOrder');
        //查询当前订单的信息
        $orderInfo = $mOrder->getByOrderId($orderId);
        $wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$orderInfo['user_id']), 'openid,subscribe');
        //$url = C('site_url')."/base/repair/orderDetail/repairId/".$orderInfo['repair_id']."/order_id/".$orderInfo['order_id'];
        $url = C('site_url').'/index.php?g=repaireast&m=repaireastRepair&a=orderDetail&repair_id='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];

        //判断是否是公共报修
        if($orderInfo['type'] == 2){
            $orderInfo['project_child_name'] = $orderInfo['public_name'];
        }

        //if($wechatUserInfo['subscribe']) {
        if($accountId == 1){
            $array = array(
                'first' => array("value" => '您的维修订单已取消！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['project_child_name'],"color" => "#173177" ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 39){
            $array = array(
                'first' => array("value" => '您的维修订单已取消！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 47){
            $array = array(
                'first' => array("value" => '您的维修订单已取消！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 38){
            $array = array(
                'first' => array("value" => '您的维修订单已取消！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else{
            $array = array(
                'first' => array("value" => '您的维修订单已取消！','color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['real_name'] ),
                'keyword2' => array("value" => $orderInfo['community_name'].$orderInfo['building_name'].$orderInfo['floor_name'].$orderInfo['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $orderInfo['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }

        if ($accountId == 1) {
            $template_id = 'QoyqfE9ayEaJAjtSr6AOpYWNdX93lxwyCBw19gGmbbo';
        }else if($accountId == 39){
            $template_id = 'Qy9uHHsRoe7dif8KouCRFWbBDxG-EnxnumkWrnX4fT8';
        }else if($accountId == 47){
            $template_id = 'GQV3ELwQOrTfeW1tFZusyBuBosRf90RJYPG4yCJ4BjI';
        }else if($accountId == 38){
            $template_id = '0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y';
        }else if($accountId == 60){
            //云感测试
            $template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
        }
        $result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);

        return $result;
        //}
        return false;
    }

    //订单状态发生改变时均推送消息给主管
    public function sendToManager($orderId,$manager,$accountId)
    {
        $wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id' => $manager), 'openid,subscribe,wechat_id');
        $order = D('RepaireastOrder') -> where(array('order_id'=>$orderId)) -> field('status,type,repair_id,order_id,real_name,community_name,building_name,floor_name,room_name,project_child_name') -> find();
        $url = C('site_url')."/repaireast/repaireastManager/orderDetail/repair_id/".$order['repair_id']."/order_id/".$order['order_id'];
        if ($accountId == 1) {
            $template_id = 'QoyqfE9ayEaJAjtSr6AOpYWNdX93lxwyCBw19gGmbbo';
        }else if($accountId == 39){
            $template_id = 'Qy9uHHsRoe7dif8KouCRFWbBDxG-EnxnumkWrnX4fT8';
        }else if($accountId == 47){
            $template_id = 'GQV3ELwQOrTfeW1tFZusyBuBosRf90RJYPG4yCJ4BjI';
        }else if($accountId == 38){
            $template_id = '0uoTPSXgcXoBssMdHuNaRmBUOQOUZOWzC2V_iQ5Bz5Y';
        }else if($accountId == 60){
            //云感测试
            $template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
        }else{
            $template_id = '';
        }
        if($order['status'] == 0){
           $words = '维修订单已取消!';
        }elseif($order['status'] == 4){
            $words = '维修订单已挂起!';
        }elseif($order['status'] == 3){
            $words = '维修订单已接单!';
        }elseif($order['status'] == 5){
            $words = '维修订单已完成!';
        }elseif($order['status'] == 6){
            $words = '维修订单已评价!';
        }
        //判断是否是公共报修
        if($order['type'] == 2){
            $order['project_child_name'] = $order['public_name'];
        }
        //if($wechatUserInfo && $wechatUserInfo['subscribe']){
        if($accountId == 1){
            $info = array(
                'first' => array("value" => $words,'color' => '#173177'),
                'keyword1' => array("value" => $order['project_child_name'],"color" => "#173177" ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 39){
            $info = array(
                'first' => array("value" => $words,'color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 47){
            $info = array(
                'first' => array("value" => $words,'color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else if($accountId == 38){
            $info = array(
                'first' => array("value" => $words,'color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }else{
            $info = array(
                'first' => array("value" => $words,'color' => '#173177'),
                'keyword1' => array("value" => $order['real_name'] ),
                /*'keyword3' => array("value" => date('Y-m-d H:i:s',strtotime("+1 hour")),"color" => "#173177" ),*/
                'keyword2' => array("value" => $order['community_name'].$order['building_name'].$order['floor_name'].$order['room_name'],"color" => "#173177"),
                'keyword3' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
                'keyword4' => array("value" => $order['project_child_name'],"color" => "#173177"),
                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            );
        }

        $result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $info, $url);
        return $result;
        //}

        return false;
    }

	/**
	 * 维修工无法维修提交返修,发消息给用户
	 * @param array $userData	用户信息
	 * @param array $orderInfo	订单信息
	 */
	/*public function backSendMessage($order,$accountId)
	{
		$mOrder = D('RepairOrder');
		$mUser = D('User');
		$orderInfo = $mOrder->getByPk($order['order_id']);
		$repairman = $mUser->getByPk($orderInfo['repairman_id']);
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$orderInfo['user_id']), 'openid,subscribe');
		$url = C('site_url').'/index.php?g=base&m=repair&a=orderDetail&repairId='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];
		if($wechatUserInfo['subscribe']) {

				$array = array(
						'first' => array("value" => $orderInfo['real_name'].'，您的维修单已提交返修,请确认并重新下单。','color' => '#FF0000'),
						'keyword2' => array("value" => $repairman['real_name'] ),
						'keyword1' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
						'remark' => array("value" => "请点击查看！","color" => "#173177"),
				);
			
			
			
			if($accountId == 2){
				$template_id = 'ervBp_BlUtHqKsaIw0qjmFz2KXy9J1tWCF5TIhW042Q';
			}elseif($accountId==5){
				$template_id = 'p_P3GalanUy8syyholudeTR3OB5hzEuEAz-w12D_lbQ';
			}elseif($accountId==6){
				$template_id = 'DAxDdnfAhywT-lfRTsaSGOQwd96g5RQnXMTigQknWCA';
			}elseif($accountId == 4){
				$template_id = 'k203JXlZ8F8SCYUIR3uH_HBL8Uq2aAMbAIv2N1r46ec';
			}elseif($accountId == 10){
				$template_id = 'A4NBwXw1VQmYDOBzCImVstEnwLG2tvbkztK8vbJkc-I';
			}elseif($accountId == 28){
				$template_id = 'Rf7JatKFZNlX-Fji4e2AmRwCvffF8bCsUxdnsHCHAZs';
			}elseif($accountId==3){
				$template_id = 'yI0d_ILucYN4r_4lfnqsvwUOPd94K7Se7rQkUScaEiU';
			}elseif($this->wechatInfo['account_id'] == 17){
				$template_id = 'qV44STOD0tpw_b2JHWrV7TsBk3uYdjpuCIYSp5gJqb4';
			}
			$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
		}
			
	}*/
	
// 	/**
// 	 * 创建订单完成后发送短信
// 	 * @param array $userData	用户信息
// 	 * @param array $orderInfo	订单信息
// 	 */
// 	public function createOrderSendMsg($userData, $orderInfo)
// 	{
// 		//todo...
// 	}
	
// 	/**
// 	 * 订单评论发送消息
// 	 * @param array $userData	用户信息
// 	 * @param array $orderInfo 订单信息
// 	 */
// 	public function orderCommentSendMsg($userData, $orderInfo)
// 	{
// 		//todo...
// 	}
}
